package ca.biosample.robot.serial;

import java.util.Scanner;

public class InterfaceTest {

	static final String CONTROL_PORT = "COM6";
	static final String COMM_PORT = "COM5";
	static final String BARCODE_PORT = "COM3";
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		//Scanner input = new Scanner(System.in);
		//byte[] response = new byte[100];
		
		XselPort2Interface control = new XselPort2Interface(COMM_PORT);
		if(!control.isOpen()) {
			System.err.println("Dying!");
			System.exit(1);
		}
		try{Thread.sleep(100);}catch(Exception e){};
		//barcodeReader.readCode();
		//robot.sendCommand("253", "20");
		//int rlen = robot.robot.read(response);
		//System.out.println(new String(response,0,rlen));
		String data;
		
		data = control.readData();
		if(data.equals("SYNCH")) {
			System.out.println("Sending START");
			control.robot.writeString("START\r");
		}
		data = control.readData();
		if(data.equals("READY")) {
			System.out.println("Sending RUN SelST 03");
			control.robot.writeString("RUN SelST 03\r");
		}
		data = control.readData();
		if(data.contains("RET   1")) {
			if(control.readData().equals("READY")) {
				System.out.println("Sending RUN STLvl");
				control.robot.writeString("RUN STLvl\r");
			}
		}
		if(control.readData().contains("RET   1")) {
			System.out.println("Sending RUN GrpST");
			control.robot.writeString("RUN GrpST\r");
		}
		if(control.readData().contains("RET   1")) {
			System.out.println("Sending RUN GtTip");
			control.robot.writeString("RUN GtTip\r");
		}
		if(control.readData().contains("RET   1")) {
			System.out.println("Sending RUN AspST 1000");
			control.robot.writeString("RUN AspST 1000\r");
		}
		if(control.readData().contains("RET   1")) {
			System.out.println("Sending RUN DisCT 1 09 0500");
			control.robot.writeString("RUN DisCT 1 09 0500\r");
		}
		if(control.readData().contains("RET   1")) {
			System.out.println("Sending RUN DisCT 1 10 0500");
			control.robot.writeString("RUN DisCT 1 10 0500\r");
		}
		if(control.readData().contains("RET   1")) {
			System.out.println("Sending RUN RtTip");
			control.robot.writeString("RUN RtTip\r");
		}
		if(control.readData().contains("RET   1")) {
			System.out.println("Sending RUN CapST");
			control.robot.writeString("RUN CapST\r");
		}
		if(control.readData().contains("RET   1")) {
			System.out.println("Sending RUN RetST");
			control.robot.writeString("RUN RetST\r");
		}
		control.readData();
		control.close();
		System.exit(0);
	}
}
